package com.sxt.bus.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.sxt.bus.BUSConstast.BUSConstast;
import com.sxt.bus.domain.Provider;
import com.sxt.bus.service.ProviderService;
import com.sxt.bus.vo.ProviderVo;
import com.sxt.sys.SYSConstast.SYSConstast;
import com.sxt.sys.utils.ResultObj;
import com.sxt.bus.utils.DataGridView;

@RestController
@RequestMapping("provider")
public class ProviderController {
	
	
	@Autowired
	private ProviderService providerService;
	

	
	@RequestMapping("loadAllProvider")
	public DataGridView loadAllProvider(ProviderVo providerVo) {
		
		return providerService.queryAllProvider(providerVo);
	}
	
	@RequestMapping("deleteProvider")
	public ResultObj deleteProvider(ProviderVo providerVo) {
		Integer code=1;
		String msg="";
		try {
			Integer info = providerService.deleteProvider(providerVo.getId());
			code = info;
			msg = info > 0 ?SYSConstast.DELETE_LOGININFOR_TRUE:SYSConstast.DELETE_LOGININFOR_FALSE;
		} catch (Exception e) {
			code = 0;
			msg = SYSConstast.DELETE_LOGININFOR_FALSE;
		}
		return new ResultObj(code , msg);
	}
	
	@RequestMapping("updateProvider")
	public ResultObj updateProvider(ProviderVo providerVo) {
		Integer code=1;
		String msg="";
		try {
			Integer info = providerService.updateProvider(providerVo);
			code = info;
			msg = info > 0 ?BUSConstast.UPDATE_LOGININFOR_TRUE:BUSConstast.UPDATE_LOGININFOR_FALSE;
		} catch (Exception e) {
			code = 0;
			msg = BUSConstast.UPDATE_LOGININFOR_FALSE;
		}
		return new ResultObj(code , msg);
	}
	
	
	@RequestMapping("addProvider")
	public ResultObj addProvider(ProviderVo providerVo) {
		Integer code=1;
		String msg="";
		try {
			Integer info = providerService.addProvider(providerVo);
			code = info;
			msg = info > 0 ?BUSConstast.ADD_LOGININFOR_TRUE:BUSConstast.ADD_LOGININFOR_FALSE;
		} catch (Exception e) {
			code = 0;
			msg = BUSConstast.ADD_LOGININFOR_FALSE;
		}
		return new ResultObj(code , msg);
	}
	@RequestMapping("loadAllProviderForList")
	public List<Provider> loadAllProviderForList(ProviderVo providerVo){
		return providerService.loadAllProviderForList(providerVo);
	}
}
